package com.yypx.action;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.aspectj.apache.bcel.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yypx.common.utils.StringUtil;
import com.yypx.entity.StudentType;
import com.yypx.service.StudentTypeService;

@Scope("prototype")
@Component("studentTypeAction")
public class StudentTypeAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private StudentTypeService studentTypeService;
	private List<Map<String, Object>> resultList;
	private Map<String, Object> rm;
	private StudentType st;

	public String add() throws Exception {
		return "add";
	}

	public String addSave() throws Exception {
		if (StringUtil.isEmpty(getRequest().getParameter("tname"))) {
			addFieldError("tname", "类型名称不能为空");
			return "add";
		}
		StudentType studentType = new StudentType();
		studentType.setCreatedby(getUserID());
		studentType.setTname(getRequest().getParameter("tname"));
		studentType.setTdes(getRequest().getParameter("tdes"));
		studentTypeService.add(studentType);
		return "infosuccess";
	}

	public String list() throws Exception {
		List<StudentType> sList = studentTypeService.selAll();
		resultList = studentTypeService.getResultList(sList);
		return "list";
	}

	public String view() throws Exception {
		int tid = Integer.valueOf(getRequest().getParameter("tid"));
		rm = studentTypeService.getResultMap(studentTypeService.findById(tid));
		return "view";
	}

	public String edit() throws Exception {
		int tid = Integer.valueOf(getRequest().getParameter("tid"));
		st = studentTypeService.findById(tid);
		return "edit";
	}

	public String editSave() throws Exception {
		StudentType studentType = new StudentType();
		studentType.setTname(getRequest().getParameter("tname"));
		studentType.setTdes(getRequest().getParameter("tdes"));
		studentType.setTid(Integer.valueOf(getRequest().getParameter("tid")));
		studentType.setLastupdateby(getUserID());
		studentTypeService.update(studentType);
		return "infosuccess";
	}

	public String delete() throws Exception {
		try {
			int tid = Integer.valueOf(getRequest().getParameter("tid"));
			studentTypeService.delete(tid);
			return "infosuccess";
		} catch (Exception e) {
			logger.error(e.getMessage());
			return null;
		}
	}

	public void setResultList(List<Map<String, Object>> resultList) {
		this.resultList = resultList;
	}

	public List<Map<String, Object>> getResultList() {
		return resultList;
	}

	public void setRm(Map<String, Object> rm) {
		this.rm = rm;
	}

	public Map<String, Object> getRm() {
		return rm;
	}

	public void setSt(StudentType st) {
		this.st = st;
	}

	public StudentType getSt() {
		return st;
	}
}
